﻿namespace HelloKinkuma
{
    using System.ComponentModel.DataAnnotations;
    using Microsoft.Practices.Prism.Commands;
    using Microsoft.Practices.Prism.Interactivity.InteractionRequest;
    using Okazuki.MVVM.PrismSupport.Utils;
    using Okazuki.MVVM.PrismSupport.ViewModels;

    public partial class MainWindowViewModel : ValidatableViewModelBase
    {
        // Viewに通知を行う
        [AutoInit]
        public InteractionRequest<Notification> AlertRequest { get; private set; }

        // Viewからの処理の受け口
        [AutoInitCommand]
        public DelegateCommand GreetCommand { get; private set; }

        [Required(ErrorMessage = "必須入力です")]
        public string Input { get; set; }

        // 初期状態で入力値の検証を行う
        public MainWindowViewModel()
        {
            this.ValidateProperties();
        }

        // GreetCommandのExecuteに対応するメソッド
        [CommandMethod]
        private void GreetExecute()
        {
            // Viewに入力された内容を通知する
            this.AlertRequest.Raise(
                new Notification { Content = this.Input });
        }

        // GreetCommandのCanExecuteに対応するメソッド
        [CommandMethod]
        private bool CanGreetExecute()
        {
            return !this.HasErrors;
        }
    }
}
